#pickle模块 把数据存储到文件
import json
import sys
# 把数据写到文件
dict_data = {
    1000:{
        "username":"zhanyue",
        "pawordss":"abc123",
        "email":"zhanyue@163.com",
        "phone":13813813800,
        "balance":15000
    },
    1001: {
        "username": "yunhun",
        "pawordss": "abc123",
        "email": "yunhun@163.com",
        "phone": 13813813810,
        "balance": 25000
    }
}
with open("db.log","r+") as fp1:
    # fp1.write(pickle.dumps(dict_data))
    # fp1.write(bytes(json.dumps(dict_data),encoding="utf-8"))
    json.dump(dict_data,fp1)
    # r = json.loads(fp1.read())
    # print(type(r),r)
sys.exit(0)
#把数据从文件读取出来
with open("db.log","rb+") as fp:
   # retdata = pickle.loads(fp.read())
   retdata = json.loads(fp.read());
   print(retdata)
   #修改工资
   retdata['1000']["balance"]-=500
   #把原来的文件清空
   fp.truncate(0)
   #移动文件指针
   fp.seek(0)
   #把修改后的文件写进去
   # fp.write(pickle.dumps(retdata))
   fp.write(bytes(json.dumps(retdata),encoding="utf-8"))